/**
 * Project Untitled
 */

#ifndef _CONNECTION_H
#define _CONNECTION_H

#include <memory>
#include <boost/asio.hpp>

#include <sstream>
#include "Packet.h"

class Connection : public std::enable_shared_from_this<Connection> {
public:
    boost::asio::ip::tcp::socket socket;

    static std::shared_ptr<Connection> create(boost::asio::io_context& io_context, boost::asio::ip::tcp::resolver::results_type);

    /**
     * @param packet
     */
    void asyncSend(Packet& packet);

    void asyncReceive();

private:
    void asyncReceiveBody();
    void asyncReceiveHeader();
    Connection(boost::asio::io_context& io_context, boost::asio::ip::tcp::resolver::results_type results_type);
};
#endif //_CONNECTION_H